#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int calculateMinimumHP(vector<vector<int>>& d) {
        int m = d.size(), n = d[0].size();
        vector<vector<int>> as(m + 1, vector<int>(n + 1, INT_MAX));
        as[m][n - 1] = as[m - 1][n] = 1;
        for (int j = m - 1; j >= 0; j--)
        {
            for (int i = n - 1; i >= 0; i--)
            {
                as[j][i] = min(as[j + 1][i], as[j][i + 1]) - d[j][i];
                as[j][i] = max(1, as[j][i]);
            }
        }
        return as[0][0];
    }
};